import fetch from 'common/src/utils/fetch';
import UTILS from "common/src/utils/utils";
/**
 * 查询教室列表
 */
export function findClassroomList(data) {
    return fetch({
        url: '/api/baseresservice/classroomController/getClassroomInfoList',
        method: 'post',
        data
    });
}

export function findClassroomPage(data) {
    return fetch({
        url: '/api/baseresservice/classroomController/getClassroomInfoList',
        method: 'post',
        data
    });
}


/**
 * 新增教室
 */
export function addClassroom(data) {
    return fetch({
        url: '/api/baseresservice/classroom/addClassroom',
        method: 'post',
        data
    });
}

/**
 * 查询教学楼
 * @param params
 */
export function getTower(params, config) {
    const conf = {
        url: '/api/baseresservice/classroomTowerInfo/getTowerByCampus',
        method: 'GET',
        params
    };
    return fetch(_.merge(conf, config));
}

/**
 * 查询校区教学楼OR楼层
 * @param params
 * @param config
 */
export function getTowerOfcamps(params, config) {
    // const conf = {
    //   url: '/api/baseresservice/towerManagement/findTowers',
    //   method: 'GET',
    //   params
    // }
    // return fetch(_.merge(conf, config));
    return getTowerInfoByCampus(params, config);
}

/**
 * 查询单个教室信息
 * @param params
 */
export function getOneRoom(params) {
    return fetch({
        url: '/api/baseresservice/classroom/findClassroomByCode',
        method: 'GET',
        params
    });
}

/**
 * 根据codes查询教室信息
 * @param params
 */
export function getRoomsByRoomId(pageNum_, pageSize_, data) {
    return fetch({
        url: '/api/baseresservice/classroomController/getClassroomListInfo?pageNum_=' +
      pageNum_ +
      '&pageSize_=' +
      pageSize_,
        method: 'POST',
        data
    });
}
/**
 * 询教室信息
 * @param params
 */
export function selectClassRoomStage() {
    return fetch({
        url: '/api/baseresservice/classroomController/selectClassRoomStage',
        method: 'GET'
    });
}

export function findSelectList(data) {
    return findClassroomPage(data);
    // return fetch({
    //   url: '/api/baseresservice/classroom/findSelectList',
    //   method: 'post',
    //   data
    // });
}

/**
 * 根据校区查询教学楼信息
 * @author yidonge 2019-09-02
 * @param params
 */
export function getTowerInfoByCampus(params, config) {
    const conf = {
        url: '/api/baseresservice/classroomTowerInfo/getTowerByCampus',
        method: 'GET',
        params
    };
    return fetch(_.merge(conf, config));
    // return fetch({
    //   url: '/api/baseresservice/classroomTowerInfo/getTowerByCampus',
    //   method: 'GET',
    //   params
    // });
}

/**
 * 根据教室code唯一性校验
 * @author yidonge 2019-09-02
 * @param params
 */
export function uniqueCheckClassroomCode(params) {
    return fetch({
        url: '/api/baseresservice/classroomController/uniqueCheckClassroomCode',
        method: 'GET',
        params
    });
}

/**
 * 新建教室
 * @author yidonge 2019-09-02
 */
export function insertClassroom(data) {
    return fetch({
        url: '/api/baseresservice/classroomController',
        method: 'post',
        data
    });
}
/**
 * 修改教室
 * @author yidonge 2019-09-02
 */
export function updateClassroom(data) {
    return fetch({
        url: '/api/baseresservice/classroomController',
        method: 'put',
        data
    });
}

/**
 * 删除教室
 * @author yidonge 2019-09-03
 */
export function delClassroom(data) {
    return fetch({
        url: '/api/baseresservice/classroomController',
        method: 'delete',
        data
    });
}

/**
 * 批量修改教室
 * @author yidonge 2019-09-03
 */
export function batUpdateClassroom(data) {
    return fetch({
        url: '/api/baseresservice/classroomController/batchEditClassroomInfo',
        method: 'post',
        data
    });
}

/**
 *导出教室 基本信息
 * @author yidonge 2019-09-03
 */
export function exportClassroomInfo(data) {
    let url =
    '/api/baseresservice/classroomController/exportExcelClassroomInfoList';
    downloadFile(data, url, 'exportClassroomInfo.xlsx');
}

function downloadFile(data, url, fileName) {
    fetch({
        url: url,
        method: 'POST',
        data,
        responseType: 'blob'
    }).then(resp => {
        if (!resp) {
            return;
        }
        if (window.navigator && window.navigator.msSaveOrOpenBlob) {
            window.navigator.msSaveOrOpenBlob(new Blob([resp]), fileName);
        } else {
            let url;
            url = window.URL.createObjectURL(new Blob([resp]));
            let link = document.createElement('a');
            link.style.display = 'none';
            link.href = url;
            link.setAttribute('download', fileName);
            document.body.appendChild(link);
            link.click();
        }
    });
}

/**
 * 下载教室导入模板
 * @author yidonge 2019-09-03
 */
export const downloadUrl =
  '/api/baseresservice/classroomController/downloadClassroomTemplate';

/**
 * 上传教室信息
 * @author yidonge 2019-09-03
 */
export const uploadUrl =
  '/api/baseresservice/classroomController/importClassroomInfo';

/**
 * 查询教学楼列表
 * @author yidonge 2019-09-04
 */
export function findTowerPage(data) {
    return fetch({
        url: '/api/baseresservice/classroomTowerInfo/list',
        method: 'post',
        data
    });
}

/**
 * 新建（新增）教学楼
 * @author yidonge 2019-09-04
 */
export function addTower(data) {
    return fetch({
        url: '/api/baseresservice/classroomTowerInfo',
        method: 'post',
        data
    });
}

/**
 * 修改教学楼
 * @author yidonge 2019-09-04
 */
export function updateTower(data) {
    return fetch({
        url: '/api/baseresservice/classroomTowerInfo',
        method: 'put',
        data
    });
}

/**
 * 删除教学楼
 * @author yidonge 2019-09-04
 */
export function delTower(data) {
    return fetch({
        url: `/api/baseresservice/classroomTowerInfo`,
        method: 'DELETE',
        data
    });
}

/**
 *导出教学楼信息
 * @author yidonge 2019-09-04
 */
export function exportClassroomTowerInfo(data) {
    let url =
    '/api/baseresservice/classroomTowerInfo/exportExcelClassroomTowerInfoList';
    downloadFile(data, url, 'exportExcelClassroomTowerInfoList.xlsx');
}

/**
 * 查询教学楼列表
 * @author yidonge 2019-09-05
 */
export function BorTeacherPage(data) {
    return fetch({
        url: '/api/baseresservice/classroomBroTeacherRel/getListInfo',
        method: 'post',
        data
    });
}

/**
 * 批量添加指定教师信息
 * @author yidonge 2019-09-05
 */
export function addTeacher(data) {
    return fetch({
        url: '/api/baseresservice/classroomBroTeacherRel',
        method: 'post',
        data
    });
}

/**
 * 删除指定借用教师
 * @author yidonge 2019-09-05
 */
export function delTeacher(data) {
    return fetch({
        url: `/api/baseresservice/classroomBroTeacherRel`,
        method: 'DELETE',
        data
    });
}

/**
 * 查询空闲教室 分页查询
 * @author yidonge 2019-09-06
 */
export function getFreeClassroomInfoList(data) {
    return fetch({
        url: '/api/baseresservice/classroomController/getFreeClassroomInoList',
        method: 'post',
        data
    });
}

/**
 * 借用申请页面查询空闲教室
 * @author yidonge 2019-09-06
 */
export function getCanBorrowClassroomIList(data) {
    return fetch({
        url: '/api/baseresservice/classroomController/getCanBorrowClassroomIList',
        method: 'post',
        data
    });
}

/**
 * 查询教室借用 分页查询
 * @author yidonge 2019-09-09
 */
export function getClassroomApplyInfoList(data) {
    return fetch({
        url: '/api/baseresservice/classroomApply/getApplyListInfo',
        method: 'post',
        data
    });
}

/**
 * 撤销教室借用申请
 * @author yidonge 2019-09-09
 */
export function cancelClassroomApply(data) {
    let url = `/api/baseresservice/classroomApply/` + data;
    return fetch({
        url: url,
        method: 'DELETE'
    });
}

/**
 * 全量查询指定借用教师数据
 * @author yidonge 2019-09-09
 * @param params
 */
export function getAllTeacherInfo() {
    return fetch({
        url: '/api/baseresservice/classroomBroTeacherRel/getAllTeacherInfo',
        method: 'GET'
    });
}

/**
 * 新增教室借用申请
 * @author yidonge 2019-09-11
 */
export function creatClassroomApply(data) {
    return fetch({
        url: '/api/baseresservice/classroomApply',
        method: 'post',
        data
    });
}

/**
 * 修改教室借用申请
 * @author yidonge 2019-09-12
 */
export function updateClassroomApply(data) {
    return fetch({
        url: '/api/baseresservice/classroomApply',
        method: 'PUT',
        data
    });
}

/**
 * 导出教室申请单
 * @author yidonge 2019-09-11
 */
export function exportApply(params) {
    const url = '/api/baseresservice/classroomApply/exportPdfClassroomApply';
    let queryParam = '';
    for (const key in params) {
    // 去掉空参数
        if (  key === 'pageNum_' || key === 'pageSize_' || key === 'total_' || params[key] === '' ) {
            continue;
        }
        queryParam += `${key}=${params[key]}&`;
    }
    window.open(`${url}?${queryParam}`);
}

export function exportExcel(data) {
    return fetch({
        url:'/api/baseresservice/classroomApply/exportClassRoomApplyExcel',
        method: 'post',
        responseType: 'blob',
        data
    }).then(res => {
        UTILS.downloadFile(res,'教室借用申请详情表.xlsx' , 'application/vnd.ms-excel;charset=utf-8')
    })
}

/**
 * 查询教室借用 分页查询
 * @author yidonge 2019-09-15
 */
export function getClassroomReviewInfoList(data) {
    return fetch({
        url: '/api/baseresservice/classroomApply/getApplyListInfoByReview',
        method: 'post',
        data
    });
}

/**
 * 查询教室借用 分页查询
 * @author yidonge 2019-09-15
 */
export function batchApproved(data) {
    return fetch({
        url: '/api/baseresservice/classroomApply/batchApproved',
        method: 'post',
        data
    });
}

/**
 *导出教学楼信息
 * @author yidonge 2019-09-15
 */
export function exprotReviewInfo(data) {
    let url =
    '/api/baseresservice/classroomApply/exportExcelClassroomApplyList';
    downloadFile(data, url, 'exprotReviewInfo.xlsx');
}

/**
 * 查询教室借用 分页查询
 * @author yidonge 2019-09-15
 */
export function getApplyInfoByWorkflowNo(data) {
    return fetch({
        url: '/api/baseresservice/classroomApply/getApplyInfoByWorkflowNo/' + data,
        method: 'get'
    });
}
/**
 * 教室基本信息页面 分页查询
 * @author yidonge 2019-09-23
 */
export function getClassroomBasalInfoList(data) {
    return fetch({
        url: '/api/baseresservice/classroomController/getClassroomBasalInfoList',
        method: 'post',
        data
    });
}

/**
 * 条件查询的时候，因为有同名的教学楼，所以要特殊化处理code值，同名的教学楼 code为： code1，code2
 * @author yidonge 2019-09-26
 */
export function conditionQueryByDict(data) {
    return fetch({
        url: '/api/baseresservice/classroomTowerInfo/conditionQueryByDict',
        method: 'post',
        data
    });
}

/**
 * 教室使用查询
 * @author yidonge 2019-10-14
 */
export function getUsageCountClassroomInfoList(data) {
    return fetch({
        url: '/api/baseresservice/classroomOccupation/getUsageCountClassroomInfoList',
        method: 'post',
        data
    });
}

/**
 * 教学周状态明细
 * @author yidonge 2019-10-15
 */
export function classroomTeachingWeekDetail(data) {
    return fetch({
        url: '/api/baseresservice/classroomOccupation/classroomTeachingWeekDetail',
        method: 'post',
        data
    });
}

/**
 * 教室使用情况报表查询 （分页查询）
 * @author yidonge 2019-10-17
 */
export function classroomUsageReportCountQuery(data) {
    return fetch({
        url: '/api/baseresservice/classroomOccupation/classroomUsageReportCountQuery',
        method: 'post',
        data
    });
}
/**
 *导出教室使用查询报表 （分页查询）
 * @author yidonge 2019-10-17
 */
export function exportExcelClaUsageReportCount(data) {
    let url =
    '/api/baseresservice/classroomOccupation/exportExcelClaUsageReportCount';
    downloadFile(data, url, 'exportExcelClaUsageReportCount.xlsx');
}

/**
 * 按周次教室使用率查询（分页查询）
 * @author yidonge 2019-10-18
 */
export function getClassroomUsageRateByWeek(data) {
    return fetch({
        url: '/api/baseresservice/classroomOccupation/getClassroomUsageRateByWeek',
        method: 'post',
        data
    });
}

/**
 *导出教室使用查询报表 （分页查询）
 * @author yidonge 2019-10-17
 */
export function exportClassroomUsageRateByWeek(data) {
    let url =
    '/api/baseresservice/classroomOccupation/exportClassroomUsageRateByWeek';
    downloadFile(data, url, 'exportClassroomUsageRateByWeek.xlsx');
}

/**
 * 按节次教室使用率查询（分页查询）
 * @author yidonge 2019-10-22
 */
export function getClassroomUsageRateByTime(data) {
    return fetch({
        url: '/api/baseresservice/classroomOccupation/getClassroomUsageRateByTime',
        method: 'post',
        data
    });
}

/**
 *教室排课使用率节次导出 （分页查询）
 * @author yidonge 2019-10-22
 */
export function exportExcelClassroomUsageRateByTime(data) {
    let url =
    '/api/baseresservice/classroomOccupation/exportExcelClassroomUsageRateByTime';
    downloadFile(data, url, 'exportExcelClassroomUsageRateByTime.xlsx');
}


/**
 * 初始化判断管理部门是否显示
 * @author quanwei 2020-04-19
 */
export function getListInfoCount(data) {
    return fetch({
        url: '/api/baseresservice/classroomBroTeacherRel/getListInfoCount',
        method: 'post',
        data
    });
}

/**
 * 教室借用申请通过后撤销操作
 * @author quanwei 2020-04-19
 */
export function updateClassroomApplyStatusBack(id) {
    return fetch({
        url: '/api/baseresservice/classroomApply/updateClassroomApplyStatusBack?id=' + id,
        method: 'get',
        headers: { 'Content-Type': 'application/json' }
    })
}

/**
 * 获取排课教室（排课管理）
 */
export function getClassroomListForArrangement(data) {
  return fetch({
    url: '/api/baseresservice/classroomController/getClassroomListForArrangement',
    method: 'post',
    data
  })
}
